import request from "@/utils/request";
import { AxiosPromise } from "axios";
import {
  ModelList,
  ModelAdd,
  ModelAppTemplate,
  Modelallocation,
} from "./types";

// 获取小程序列表
export function getAppList<T>(data: ModelList): AxiosPromise<T> {
  return request({
    url: "/api/Apps/search",
    method: "get",
    params: data,
  });
}

// 新增小程序
export function appsAdd<T>(data: ModelAdd): AxiosPromise<T> {
  return request({
    url: "/api/Apps",
    method: "post",
    data,
  });
}

// 编辑小程序
export function appsEdit<T>(data: ModelAdd): AxiosPromise<T> {
  return request({
    url: `/api/Apps/${data.id}`,
    method: "put",
    data,
  });
}

// 删除小程序
export function appsDelete<T>(data: number): AxiosPromise<T> {
  return request({
    url: `/api/Apps/${data}`,
    method: "delete",
  });
}

// 获取-小程序下拉集合
export function appsOptions<T>({}): AxiosPromise<T> {
  return request({
    url: "/api/Apps/options",
    method: "get",
  });
}

// 小程序-绑定充值模板
export function appsTemplate<T>(data: ModelAppTemplate): AxiosPromise<T> {
  return request({
    url: `/api/Apps/${data.id}/template`,
    method: "patch",
    // data
    params: { templateId: data.templateId },
  });
}

// 通过小程序id 获取小程序信息
export function appsInfo<T>(data: number): AxiosPromise<T> {
  return request({
    url: `/api/Apps/${data}`,
    method: "get",
  });
}

// 分配小程序到分销商
export function allocationDistApp<T>(data: Modelallocation): AxiosPromise<T> {
  return request({
    url: `/api/VisibleApp/distributor`,
    method: "post",
    data,
  });
}

// 分配小程序到用户
export function allocationUserApp<T>(data: Modelallocation): AxiosPromise<T> {
  return request({
    url: `/api/VisibleApp/user`,
    method: "post",
    data,
  });
}
